home *** CD-ROM | disk | FTP | other *** search
- /*
-
- GetRAMCache XFCN v1.1
-
- ©1990-1 Apple Computer, Inc.; by Mike Byrne
-
- This XFCN returns the value set in PRAM for the RAM cache. If the RAM cache is turned off, it
- returns 0. Otherwise, it returns the value of the cache. It can only be described as evil code.
-
- Form:
- GetRAMCache()
-
- # the MPW 3.2 build commands:
- C -b GetRAMCache.c -mbg off
- Link -w -t STAK -c WILD -rt XFCN=609 ∂
- -m ENTRYPOINT ∂
- -sg RamCache ∂
- GetRAMCache.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "teststack"
- */
-
- #include <Types.h>
- #include <Packages.h>
- #include <string.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include "HyperXCmd.h"
-
- #define NULL (long) 0
- #define NIL (long) 0
-
- #define kNumParams 0
-
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
-
-
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- /* variable declarations */
- Byte* pRam;
- short cacheSize;
- short cacheOn;
- Str255 retString;
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.1, ©1990 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "GetRamCache syntax is 'GetRAMCache()");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* not a copyright or help request. */
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "Error: GetRamCache syntax is 'GetRAMCache()'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* set the address and get values. How does this really work? pRam is a pointer to a byte.
- The byte that specifies the RAM cache size is at 0x020A (hex), so the pointer is set to
- that. Then, the pointer is incremented one and the byte is masked to get the bit that
- specifies if the cache is on or off. Yeah, it's ugly. */
-
- (long) pRam = 0x020A;
- cacheSize = (*pRam)*32;
- NumToString(cacheSize, retString);
- p2cstr(retString);
- pRam++;
- cacheOn = (*pRam) & 0x20;
- if (!cacheOn) {
- ErrorBack(paramPtr, "0");
- return;
- }
- ErrorBack(paramPtr, retString);
- return;
-
- }
-
-
-
-
-
-
- /* allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1));
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
-
- /* move high and lock down all parameters
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]);
- HLock(paramPtr->params[i]);
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XCmdBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);}
- }
-